import { Component, OnInit, Input } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { map } from 'rxjs/operators';
import { WaterService } from './../../../core/services/water.service';

interface WaterData {
  key: string;
  cas: string;
  cas_name: string;
  val: number;
  v1: number;
  v2: number;
  v3: number;
  v4: number;
  type: string;
  round: number;
  name: string;
}

@Component({
  selector: 'smart-table-basic',
  templateUrl: './smart-table.component.html',
  styleUrls: ['./smart-table.component.scss'],
})
export class SmartTableComponent implements OnInit {
  @Input() properties: any;
  constructor(private http: HttpClient, private waterService: WaterService) {}
  isLoading = true;
  selectedIndex = 4;
  @Input() dataList: WaterData[];

  ngOnInit() {
    this.getWater1(this.properties.name);
  }
  selectTab(args: any[]) {
    if (args.length > 0) {
      if (args[0].index == 0) {
        this.getWater1(this.properties.name);
      } else if (args[0].index == 1) {
        this.getWater2(this.properties.name);
      } else if (args[0].index == 2) {
        this.getWater3(this.properties.name);
      } else if (args[0].index == 3) {
        this.getWater4(this.properties.name);
      } else {
        this.getWater5(this.properties.name);
      }
    }
  }
  getWater1(fid) {
    this.waterService.getWater1().subscribe((res) => {
      let dt = res.filter((row) => {
        return row.name2 === fid;
      });
      this.dataList = dt;
    });
  }

  getWater2(fid) {
    this.waterService.getWater2().subscribe((res) => {
      let dt = res.filter((row) => {
        return row.name2 === fid;
      });
      this.dataList = dt;
    });
  }

  getWater3(fid) {
    this.waterService.getWater3().subscribe((res) => {
      let dt = res.filter((row) => {
        return row.name2 === fid;
      });
      this.dataList = dt;
    });
  }

  getWater4(fid) {
    this.waterService.getWater4().subscribe((res) => {
      let dt = res.filter((row) => {
        return row.name2 === fid;
      });
      this.dataList = dt;
    });
  }

  getWater5(fid) {
    this.waterService.getWater5().subscribe((res) => {
      let dt = res.filter((row) => {
        return row.name2 === fid;
      });
      this.dataList = dt;
    });
  }
}
